package com.deepnet.lottery.utils;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.reflect.Field;
import java.security.MessageDigest;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.http.util.EncodingUtils;
import org.xutils.x;
import org.xutils.common.util.DensityUtil;
import org.xutils.image.ImageOptions;

import com.deepnet.lottery.R;
import com.deepnet.lottery.calendar.Lunar;

import Decoder.BASE64Decoder;
import Decoder.BASE64Encoder;
import android.app.Activity;
import android.app.ActionBar.LayoutParams;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.Signature;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Environment;
import android.provider.MediaStore;
import android.telephony.TelephonyManager;
import android.util.Base64;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnLayoutChangeListener;
import android.view.ViewGroup;
import android.webkit.CookieManager;
import android.webkit.CookieSyncManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

/**
 * Created by Administrator on 2016/7/11.
 */
public class Utils {
	static long t1 = 0;
	/**
	 * 请求条数
	 */
	public static final String mPageSize = "30";
	public static String encode(String content) {
		try {
			MessageDigest digest = MessageDigest.getInstance("MD5");
			digest.update(content.getBytes());
			return getEncode16(digest);
			// return getEncode32(digest);
		} catch (Exception e) {

		}
		return null;
	}

	/**
	 * 32位加密
	 *
	 * @param digest
	 * @return
	 */
	private static String getEncode32(MessageDigest digest) {
		StringBuilder builder = new StringBuilder();
		for (byte b : digest.digest()) {
			builder.append(Integer.toHexString((b >> 4) & 0xf));
			builder.append(Integer.toHexString(b & 0xf));
		}
		// return builder.toString().toLowerCase(); // 小写
		// return builder.toString().toUpperCase(); // 大写
		// java.lang.String.toUpperCase(Locale locale)
		// 方法将在此字符串中的所有字符为大写的规则给定的Locale.
		// return builder.toString().toUpperCase(Locale.getDefault()); // 大写
		return builder.toString();
	}

	public static void setImage(Context context, int i, TextView mText) {

		Drawable drawable = context.getResources().getDrawable(i);
		drawable.setBounds(0, 0, 35, 35);
		mText.setCompoundDrawables(drawable, null, null, null);
	}

	public static void setTag(Context context, int mWidth, int mHeigh, TextView mTextStr, int i) {
		// TODO Auto-generated method stub
		Resources re = context.getResources();
		Drawable one = re.getDrawable(i);
		one.setBounds(0, 0, mWidth, mHeigh);
		mTextStr.setCompoundDrawables(one, null, null, null); // 设置顶图标

	}

	public static void setTopTag(Context context, int mWidth, int mHeigh, TextView mTextStr, int i, String s) {
		// TODO Auto-generated method stub
		Resources re = context.getResources();
		Drawable one = re.getDrawable(i);
		one.setBounds(0, 0, mWidth, mHeigh);
		mTextStr.setCompoundDrawables(null, one, null, null); // 设置顶图标
		mTextStr.setText(s);
	}

	/**
	 * 16位加密
	 *
	 * @param digest
	 * @return
	 */
	private static String getEncode16(MessageDigest digest) {
		StringBuilder builder = new StringBuilder();
		for (byte b : digest.digest()) {
			builder.append(Integer.toHexString((b >> 4) & 0xf));
			builder.append(Integer.toHexString(b & 0xf));
		}

		// 16位加密，从第9位到25位
		// return builder.substring(8, 24).toString().toUpperCase();
		return builder.substring(8, 24).toString().toUpperCase();
	}

	/**
	 * 字符串转化为bASE64
	 *
	 * @param--bstr
	 * @return String
	 */
	public static String StringToBase64(String mStr) {
		return new BASE64Encoder().encode(mStr.getBytes());
	}

	/**
	 * 解码
	 *
	 * @param str
	 * @return string
	 */
	public static String decode(String str) {
		byte[] bt = null;
		String str2 = null;
		try {
			BASE64Decoder decoder = new BASE64Decoder();
			bt = decoder.decodeBuffer(str);
			str2 = EncodingUtils.getString(bt, "UTF-8");
		} catch (IOException e) {
			e.printStackTrace();
		}

		return str2;
	}

	/**
	 * 功能描述:判断电话号码格式
	 * 
	 * @param wangJiMiMaActivity
	 *
	 * @param mobiles
	 * @return
	 */

	public static boolean isMobileNO(String mobiles) {
		String telRegex = "[1][3578]\\d{9}";// "[1]"代表第1位为数字1，"[358]"代表第二位可以为3、5、8中的一个，"\\d{9}"代表后面是可以是0～9的数字，有9位。
		return mobiles.matches(telRegex);
	}

	/**
	 * 功能描述：判断电子邮箱格�?
	 *
	 * @param email
	 * @return
	 */

	public static boolean isEmail(String email) {

		String str = "^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$";

		Pattern p = Pattern.compile(str);

		Matcher m = p.matcher(email);

		return m.matches();

	}

	/**
	 * 功能描述：正则表达式判断邮政编码格式
	 *
	 * @param emailNo
	 * @return
	 */

	public static boolean isEmailNo(String emailNo) {
		String str = "^[1-9]\\d{5}$";
		Pattern p = Pattern.compile(str);
		Matcher m = p.matcher(emailNo);
		return m.matches();
	}

	/** 作用: SD卡根目录 */
	public static final String PATH = Environment.getExternalStorageDirectory().getPath();
	/** 作用: 数据文件夹 */
	public static final String PATH_ICON = PATH + "/TCM/DK/";

	/**
	 * 功能描述: 创建文件夹
	 */
	public static void createFile(String name, Context c) {

		if (!isHavaSDCard()) {
			Toast.makeText(c, "请插入SD卡，否则无法下载阅读内容", Toast.LENGTH_SHORT).show();
			return;
		}
		File dir = new File(name);
		if (!dir.exists()) {
			dir.mkdirs();
		}
	}

	/**
	 * 功能描述: 删除文件或文件夹
	 */
	public static void deleteFile(File file) {

		if (file.exists()) {
			if (file.isFile()) {
				file.delete();
			} else if (file.isDirectory()) {
				File files[] = file.listFiles();
				for (int i = 0; i < files.length; i++) {
					deleteFile(files[i]);
				}
			}
			file.delete();
		}
	}

	/**
	 * 功能描述: 是否有SD卡
	 */
	public static boolean isHavaSDCard() {

		if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
			return true;
		}

		return false;
	}

	/**
	 * 打电话
	 *
	 * @param context
	 * @param mobile
	 */
	public static void daDianHua(Context context, String mobile) {

		Intent intent = new Intent();
		intent.setAction(Intent.ACTION_CALL);
		intent.setData(Uri.parse("tel:" + mobile));
		context.startActivity(intent);
	}

	/**
	 * 获取手机型号
	 *
	 * @return
	 */
	public static String getPhoneModel() {
		String model = "";
		try {
			model = android.os.Build.MODEL;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return model;
	}

	/**
	 * 获取手机串号
	 *
	 * @param context
	 * @return
	 */
	public static String getPhoneImei(Context context) {

		TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
		String imei = telephonyManager.getDeviceId();

		return imei;
	}

	/**
	 * 获取本应用的版本号
	 *
	 * @param context
	 * @return
	 */

	public static String getCurrVersionName(Context context) {
		String versionCode = null;
		PackageManager manager = context.getPackageManager();
		try {
			PackageInfo info = manager.getPackageInfo(context.getPackageName(), 0);
			versionCode = info.versionName;
		} catch (PackageManager.NameNotFoundException e) {
			e.printStackTrace();
		}
		return versionCode;
	}

	/**
	 * bitmap转base64
	 *
	 * @param bitmap
	 * @return
	 */
	public static String bitmapToBase64(Bitmap bitmap) {

		String result = null;
		ByteArrayOutputStream baos = null;
		try {
			if (bitmap != null) {
				baos = new ByteArrayOutputStream();
				bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);

				baos.flush();
				baos.close();

				byte[] bitmapBytes = baos.toByteArray();
				result = Base64.encodeToString(bitmapBytes, Base64.DEFAULT);
			}
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				if (baos != null) {
					baos.flush();
					baos.close();
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return result;
	}

	/**
	 * base64转bitmap
	 *
	 * @param base64Data
	 * @return
	 */
	public static Bitmap base64ToBitmap(String base64Data) {
		byte[] bytes = Base64.decode(base64Data, Base64.DEFAULT);
		return BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
	}

	/**
	 * 截取数字
	 *
	 * @param content
	 * @return
	 */

	public static String getNumbers(String content) {
		Pattern pattern = Pattern.compile("\\d+");
		Matcher matcher = pattern.matcher(content);
		while (matcher.find()) {
			return matcher.group(0);
		}
		return "";
	}

	/**
	 * 截取非数字
	 *
	 * @param content
	 * @return
	 */
	public static String splitNotNumber(String content) {
		Pattern pattern = Pattern.compile("\\D+");
		Matcher matcher = pattern.matcher(content);
		while (matcher.find()) {
			return matcher.group(0);
		}
		return "";
	}

	public static String getmTM(String showText) {
		String typeTm = null;
		if (showText.equals("正一")) {
			typeTm = "1";
		} else if (showText.equals("正二")) {
			typeTm = "2";
		} else if (showText.equals("正三")) {
			typeTm = "3";
		} else if (showText.equals("正四")) {
			typeTm = "4";
		} else if (showText.equals("正五")) {
			typeTm = "5";
		} else if (showText.equals("正六")) {
			typeTm = "6";
		} else if (showText.equals("特码")) {
			typeTm = "7";
		}
		return typeTm;
	}

	public static void mDisPlay(ImageView micon, String mUrl) {
		ImageOptions op = new ImageOptions.Builder().setSize(DensityUtil.dip2px(120), DensityUtil.dip2px(120))
				.setRadius(DensityUtil.dip2px(5))
				// 如果ImageView的大小不是定义为wrap_content, 不要crop.
				.setCrop(true)
				// 加载中或错误图片的ScaleType
				// .setPlaceholderScaleType(ImageView.ScaleType.MATRIX)
				.setImageScaleType(ImageView.ScaleType.CENTER_CROP)
				// 设置加载过程中的图片
				.setLoadingDrawableId(R.drawable.loadding)
				// 设置加载失败后的图片
				.setFailureDrawableId(R.drawable.loadding)
				// 设置使用缓存
				.setUseMemCache(true)
				// 设置支持gif
				.setIgnoreGif(false)
				// 设置显示圆形图片
				.setCircular(false).setSquare(true).build();

		x.image().bind(micon, mUrl, op);
	}

	public static void mDisPlayHead(ImageView micon, String mUrl) {
		ImageOptions op = new ImageOptions.Builder()
				// 如果ImageView的大小不是定义为wrap_content, 不要crop.
				.setCrop(true)
				// 加载中或错误图片的ScaleType
				// .setPlaceholderScaleType(ImageView.ScaleType.MATRIX)
				.setImageScaleType(ImageView.ScaleType.CENTER_CROP)
				// 设置加载过程中的图片
				.setLoadingDrawableId(R.drawable.loadding)
				// 设置加载失败后的图片
				.setFailureDrawableId(R.drawable.header)
				// 设置使用缓存
				.setUseMemCache(true)
				// 设置支持gif
				.setIgnoreGif(false)
				// 设置显示圆形图片
				.setCircular(false).setSquare(true).build();
		x.image().bind(micon, mUrl, op);
	}

	/**
	 * ---清除cookie
	 * 
	 * @param context
	 */

	public static void clearCookies(Context context) {
		CookieSyncManager cookieSyncMngr = CookieSyncManager.createInstance(context);
		CookieManager cookieManager = CookieManager.getInstance();
		cookieManager.removeAllCookie();
	}

	public static void mSetLable0(Context context, TextView mText, String mT, String Sx, String Wx) {
		Pattern p = Pattern.compile("[0-9\\.]+");
		Matcher m = p.matcher(mT);
		while (m.find()) {
			System.out.print(m.group());
			String t = m.group();
			int res = getImageId("ball" + t);
			Resources re = context.getResources();
			Drawable one = re.getDrawable(res);
			one.setBounds(0, 0, 50, 50);
			mText.setCompoundDrawables(null, one, null, null); // 设置顶图标
		}
		mText.setText(Sx + "/" + Wx);
	}

	public static void mSetLable1(Context context, TextView mText, String mT, String Sx, String Wx, int mHeight,
			int mWidth) {
		Pattern p = Pattern.compile("[0-9\\.]+");
		Matcher m = p.matcher(mT);
		while (m.find()) {
			System.out.print(m.group());
			String t = m.group();
			int res = getImageId("ball" + t);
			Resources re = context.getResources();
			Drawable one = re.getDrawable(res);
			one.setBounds(0, 0, mWidth, mHeight);
			mText.setCompoundDrawables(null, one, null, null); // 设置顶图标
		}
		mText.setText(Sx + "/" + Wx);
	}

	public static void mSetLable2(Context context, TextView mText, String mT, int mHeight, int mWidth) {
		Pattern p = Pattern.compile("[0-9\\.]+");
		Matcher m = p.matcher(mT);
		while (m.find()) {
			System.out.print(m.group());
			String t = m.group();
			int res = getImageId("ball" + t);
			Resources re = context.getResources();
			Drawable one = re.getDrawable(res);
			one.setBounds(0, 0, mWidth, mHeight);
			mText.setCompoundDrawables(null, one, null, null); // 设置顶图标
		}
	}

	public static void mSetLable(Context context, TextView mText, String mT, int mHeight, int mWidth) {
		try {

			mText.setTextColor(Color.LTGRAY);
			Pattern p = Pattern.compile("[0-9\\.]+");
			Matcher m = p.matcher(mT);
			while (m.find()) {
				System.out.print(m.group());
				String t = m.group();
				int res = getImageId("ball" + t);

				Resources re = context.getResources();
				Drawable one = re.getDrawable(res);

				one.setBounds(0, 0, mWidth, mHeight);
				mText.setCompoundDrawables(null, one, null, null); // 设置顶图标
			}

			String s = mT.substring(0, 3).replace(",", "/");

			mText.setText(s);
		} catch (IndexOutOfBoundsException e) {
			// TODO: handle exception
		}

	}
	public static void mSetLable4(Context context, TextView mText, String mT, String Sx, String Wx, int mHeight,
			int mWidth) {
		Pattern p = Pattern.compile("[0-9\\.]+");
		Matcher m = p.matcher(mT);
		while (m.find()) {
			System.out.print(m.group());
			String t = m.group();
			int res = getImageId("ball" + t);
			Resources re = context.getResources();
			Drawable one = re.getDrawable(res);
			Drawable two = re.getDrawable(R.drawable.add);
			one.setBounds(0, 0, mWidth, mHeight);
			two.setBounds(0, 0, 25, 25);
			
			mText.setCompoundDrawables(null, one, two, null); // 设置顶图标
			mText.setGravity(Gravity.TOP);
		}
		mText.setText(Sx + "/" + Wx);
	}
	public static int getImageId(String mName) {
		int res_ID = 0;
		Class drawable = R.drawable.class;
		Field field = null;
		try {
			field = drawable.getField(mName);
			res_ID = field.getInt(field.getName());
		} catch (Exception e) {
		}
		return res_ID;
	}

	public static Lunar getChineseTime(String mDtate) {

		Lunar lunar = null;
		try {
			Calendar today = Calendar.getInstance();
			today.setTime(Lunar.chineseDateFormat.parse(mDtate));
			lunar = new Lunar(today);

			// System.out.println("北京时间：" +
			// chineseDateFormat.format(today.getTime())
			// + " 农历" + lunar);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return lunar;

	}

	/**
	 * 获取Name
	 * 
	 * @return
	 */
	public static String StrShengXiaoName(List<Map<String, Object>> all, String mStr) {

		StringBuilder sb = new StringBuilder();
		List<String> StrList = new ArrayList<String>();

		for (int i = 0; i < all.size(); i++) {
			String id = (String) all.get(i).get(mStr);
			StrList.add(id);
		}

		for (int i = 0; i < StrList.size(); i++) {

			String Cid = StrList.get(i);
			if (i == StrList.size() - 1) {
				sb.append(Cid).toString();
			} else {
				sb.append(Cid).toString();
				sb.append(",");
			}
		}

		return sb.toString();
	}

	public static void getSign(Context ctx) {
		try {
			PackageInfo packageInfo = ctx.getPackageManager().getPackageInfo("com.deepnet.lottery",
					PackageManager.GET_SIGNATURES);
			Signature[] signs = packageInfo.signatures;
			Signature sign = signs[0];
			MessageDigest md1 = MessageDigest.getInstance("MD5");
			md1.update(sign.toByteArray());
			byte[] digest = md1.digest();
			String res = toHexString(digest);
			Log.e("------------", "apk md5 = " + res);
			MessageDigest md2 = MessageDigest.getInstance("SHA1");
			md2.update(sign.toByteArray());
			byte[] digest2 = md2.digest();
			String res2 = toHexString(digest2);
			Log.e("---------------", "apk SHA1 = " + res2);
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	private static String toHexString(byte[] block) {
		StringBuffer buf = new StringBuffer();
		int len = block.length;
		for (int i = 0; i < len; i++) {
			byte2hex(block[i], buf);
			if (i < len - 1) {
				buf.append(":");
			}
		}
		return buf.toString();
	}

	private static void byte2hex(byte b, StringBuffer buf) {
		char[] hexChars = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
		int high = ((b & 0xf0) >> 4);
		int low = (b & 0x0f);
		buf.append(hexChars[high]);
		buf.append(hexChars[low]);
	}

	/**
	 * 校验银行卡卡号
	 * 
	 * @param cardId
	 * @return
	 */
	public static boolean checkBankCard(String cardId) {
		char bit = getBankCardCheckCode(cardId.substring(0, cardId.length() - 1));
		if (bit == 'N') {
			return false;
		}
		return cardId.charAt(cardId.length() - 1) == bit;
	}

	/**
	 * 从不含校验位的银行卡卡号采用 Luhm 校验算法获得校验位
	 * 
	 * @param nonCheckCodeCardId
	 * @return
	 */
	public static char getBankCardCheckCode(String nonCheckCodeCardId) {
		if (nonCheckCodeCardId == null || nonCheckCodeCardId.trim().length() == 0
				|| !nonCheckCodeCardId.matches("\\d+")) {
			// 如果传的不是数据返回N
			return 'N';
		}
		char[] chs = nonCheckCodeCardId.trim().toCharArray();
		int luhmSum = 0;
		for (int i = chs.length - 1, j = 0; i >= 0; i--, j++) {
			int k = chs[i] - '0';
			if (j % 2 == 0) {
				k *= 2;
				k = k / 10 + k % 10;
			}
			luhmSum += k;
		}
		return (luhmSum % 10 == 0) ? '0' : (char) ((10 - luhmSum % 10) + '0');
	}

	// 获取时间差
	public static int getMinutesDiff(String startDate, String endDate) {
		int ret = 0;

		String startDateStr[] = startDate.split(":");
		String endDateStr[] = endDate.split(":");
		if (startDateStr[0].startsWith("0")) {
			startDateStr[0] = startDateStr[0].substring(1);
		}
		if (startDateStr[1].startsWith("0")) {
			startDateStr[1] = startDateStr[1].substring(1);
		}
		if (endDateStr[0].startsWith("0")) {
			endDateStr[0] = endDateStr[0].substring(1);
		}
		if (endDateStr[1].startsWith("0")) {
			endDateStr[1] = endDateStr[1].substring(1);
		}
		int s = Integer.parseInt(startDateStr[0]) * 60 + Integer.parseInt(startDateStr[1]);
		int e = Integer.parseInt(endDateStr[0]) * 60 + Integer.parseInt(endDateStr[1]);
		ret = e - s;
		return ret;

	}

	public static void saveImageToGallery(Context context, Bitmap bmp) {
		// 首先保存图片
		File appDir = new File(Environment.getExternalStorageDirectory(), "czx");
		if (!appDir.exists()) {
			appDir.mkdir();
		}
		String fileName = System.currentTimeMillis() + ".jpg";
		File file = new File(appDir, fileName);
		try {
			FileOutputStream fos = new FileOutputStream(file);
			bmp.compress(CompressFormat.JPEG, 100, fos);
			fos.flush();
			fos.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}

		// 其次把文件插入到系统图库
		try {
			MediaStore.Images.Media.insertImage(context.getContentResolver(), file.getAbsolutePath(), fileName, null);
			Toast.makeText(context, "已存入手机相册", 1).show();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
			Toast.makeText(context, "保存失败", 1).show();
		}
		// 最后通知图库更新
		context.sendBroadcast(
				new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(new File(file.getPath()))));

	}

	public static int mPicHeight(String murl) {
		int value = murl.lastIndexOf("/") + 1;
		String mheight = murl.substring(value + 4, value + 8);
		return Integer.valueOf(mheight);

	}

	public static int mPicWidth(String murl) {
		int value = murl.lastIndexOf("/") + 1;
		String mWidth = murl.substring(value, value + 4);
		return Integer.valueOf(mWidth);

	}

	public static String getType(String mStr) {
		String type;
		if (mStr.equals("50")||mStr.equals("100")||mStr.equals("200")||mStr.equals("500")) {
			
			type = "2";
		}else{
			
			type = "1";
		}
		
		return type;

	}
	public  static void setInputSoftVis(final Activity c,int screenHeight, LinearLayout v){
		//阀值设置为屏幕高度的1/3
	 final int	keyHeight = screenHeight/3;
		v.addOnLayoutChangeListener(new OnLayoutChangeListener() {
			
			@Override
			public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight,
					int oldBottom) {
				// TODO Auto-generated method stub
				//old是改变前的左上右下坐标点值，没有old的是改变后的左上右下坐标点值
				
//				System.out.println(oldLeft + " " + oldTop +" " + oldRight + " " + oldBottom);
//				System.out.println(left + " " + top +" " + right + " " + bottom);
				
				
				//现在认为只要控件将Activity向上推的高度超过了1/3屏幕高，就认为软键盘弹起
				if(oldBottom != 0 && bottom != 0 &&(oldBottom - bottom > keyHeight)){
					
					Toast.makeText(c, "监听到软键盘弹起...", Toast.LENGTH_SHORT).show();
				
				}else if(oldBottom != 0 && bottom != 0 &&(bottom - oldBottom > keyHeight)){
					
					Toast.makeText(c, "监听到软件盘关闭...", Toast.LENGTH_SHORT).show();
				
				} 
			}
		}); 
	}

	public static void setToast(Context context,String str) {
		// TODO Auto-generated method stub
		
		if(t1==0){//第一次单击，初始化为本次单击的时间
	         t1= (new Date()).getTime();
	         T(context,str);
	      }else{
	         long curTime = (new Date()).getTime();//本地单击的时间
	         if(curTime-t1>3*1000){
	            //间隔5秒允许点击，可以根据需要修改间隔时间
	            t1 = curTime;//当前单击事件变为上次时间
	            T(context,str);
	         }
	      }
		
	}
 
	
	static void T(Context context,String str){
		 Toast.makeText(context, str, Toast.LENGTH_SHORT).show();
	}
}
